#include "event_app.h"
#include "sound_board.h"
#include "real_time_app.h"
#include "device_parameter.h"

/**
 * @brief 获取是否在允许的时间内
 *
 * @return bool - 获取状态（true：是 false：否）
 */
static bool SoundGetIfItIsWithinTheAllowedTime(void);

static bool SoundGetIfItIsWithinTheAllowedTime(void)
{
  uint8_t Hour = 0, Minute = 0;
  uint32_t StartTimestamp = 0, EndTimestamp = 0, NowTimestamp = 0;
  uint8_t StartHour = 0, StartMinute = 0, EndHour = 0, EndMinute = 0;

  {
    EndHour = GetNoDisturbingEndHour();
    StartHour = GetNoDisturbingStartHour();
    EndMinute = GetNoDisturbingEndMinute();
    StartMinute = GetNoDisturbingStartMinute();

    if ((StartHour == 0) && (StartMinute == 0) && (EndHour == 0) && (EndMinute == 0))
      return true;
  }

  {
    RealTimeRtcGetCurrentTime(NULL, NULL, NULL, &Hour, &Minute, NULL, NULL);

    NowTimestamp = (Hour * 60) + Minute;
    EndTimestamp = (EndHour * 60) + EndMinute;
    StartTimestamp = (StartHour * 60) + StartMinute;

    if (EndTimestamp <= StartTimestamp)
    {
      EndTimestamp += 24 * 60;
    }

    if (NowTimestamp < StartTimestamp)
    {
      NowTimestamp += 24 * 60;
    }

    if ((NowTimestamp >= StartTimestamp) && (NowTimestamp < EndTimestamp))
      return true;
  }

  return false;
}

bool SoundGetDoNotDisturbFlag(void)
{
  if (SoundGetIfItIsWithinTheAllowedTime() == true)
    return false;

  return true;
}
